home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-01 | 9.7 KB | 432 lines | [TEXT/MPS ] |
- ;
- ; File: Synchronization.a
- ;
- ; Contains: Synchronization Interfaces
- ;
- ; Version: Technology: System 8
- ; Release: Universal Interfaces 3.0d3 on Copland DR1
- ;
- ; Copyright: © 1984-1996 by Apple Computer, Inc. All rights reserved.
- ;
- ; Bugs?: If you find a problem with this file, send the file and version
- ; information (from above) and the problem description to:
- ;
- ; Internet: apple.bugs@applelink.apple.com
- ; AppleLink: APPLE.BUGS
- ;
- ;
- IF &TYPE('__SYNCHRONIZATION__') = 'UNDEFINED' THEN
- __SYNCHRONIZATION__ SET 1
-
- IF &TYPE('__TYPES__') = 'UNDEFINED' THEN
- include 'Types.a'
- ENDIF
- IF &TYPE('__KERNEL__') = 'UNDEFINED' THEN
- include 'Kernel.a'
- ENDIF
- IF FOR_SYSTEM8_PREEMPTIVE THEN
- ; Note: Lock, ReadWriteLock, and CountingSemaphore data structures must be LONG WORD ALIGNED in memory!
- Lock RECORD 0
- theInfo ds.l 2 ; offset: $0 (0)
- sizeof EQU * ; size: $8 (8)
- ENDR
- ; typedef struct Lock * LockPtr
-
- ReadWriteLock RECORD 0
- theInfo ds.l 5 ; offset: $0 (0)
- sizeof EQU * ; size: $14 (20)
- ENDR
- ; typedef struct ReadWriteLock * ReadWriteLockPtr
-
- CountingSemaphore RECORD 0
- theInfo ds.l 6 ; offset: $0 (0)
- sizeof EQU * ; size: $18 (24)
- ENDR
- ; typedef struct CountingSemaphore * CountingSemaphorePtr
-
- ; typedef OptionBits LockOptions
-
-
- kLockDisablesSwis EQU $00000001 ; disable software interrupts while locked
- kLockAdjustsPriorities EQU $00000002 ; lock prevents priority inversion
- kLockDisablesCompletionRoutines EQU $00000004 ; disable software interrupts and system 7 completion routines while locked
- ; typedef void * InterruptState
-
- ;
- ; Simple lock routines
- ; Locks may be created with the kLockDisablesSwis and/or kLockDisablesCompletionRoutines options,
- ; but no others.
- ;
- ;
- ; extern OSStatus CreateLock(Lock *theLock, LockOptions theOptions)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION CreateLock
- ENDIF
-
- ;
- ; extern OSStatus DeleteLock(Lock *theLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION DeleteLock
- ENDIF
-
- ;
- ; extern OSStatus BeginLockedSection(Lock *theLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BeginLockedSection
- ENDIF
-
- ;
- ; extern OSStatus TryBeginLockedSection(Lock *theLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION TryBeginLockedSection
- ENDIF
-
- ;
- ; extern OSStatus EndLockedSection(Lock *theLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION EndLockedSection
- ENDIF
-
- ;
- ; extern Boolean IsLockedSectionHeld(Lock *theLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION IsLockedSectionHeld
- ENDIF
-
- ;
- ; Reader/writer lock routines
- ; ReadWriteLocks may be created with the kLockDisablesSwis, kLockDisablesCompletionRoutines,
- ; and/or kLockAdjustsPriorities options.
- ;
- ;
- ; extern OSStatus CreateReadWriteLock(ReadWriteLock *theReadWriteLock, LockOptions theOptions)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION CreateReadWriteLock
- ENDIF
-
- ;
- ; extern OSStatus DeleteReadWriteLock(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION DeleteReadWriteLock
- ENDIF
-
- ;
- ; extern OSStatus BeginReadLockedSection(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BeginReadLockedSection
- ENDIF
-
- ;
- ; extern OSStatus TryBeginReadLockedSection(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION TryBeginReadLockedSection
- ENDIF
-
- ;
- ; extern OSStatus EndReadLockedSection(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION EndReadLockedSection
- ENDIF
-
- ;
- ; extern OSStatus BeginWriteLockedSection(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BeginWriteLockedSection
- ENDIF
-
- ;
- ; extern OSStatus TryBeginWriteLockedSection(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION TryBeginWriteLockedSection
- ENDIF
-
- ;
- ; extern OSStatus EndWriteLockedSection(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION EndWriteLockedSection
- ENDIF
-
- ;
- ; extern OSStatus ChangeWriteLockToReadLock(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION ChangeWriteLockToReadLock
- ENDIF
-
- ;
- ; extern Boolean IsReadLockedSectionHeld(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION IsReadLockedSectionHeld
- ENDIF
-
- ;
- ; extern Boolean IsWriteLockedSectionHeld(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION IsWriteLockedSectionHeld
- ENDIF
-
- ;
- ; extern ItemCount GetReadWriteLockReaderCount(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION GetReadWriteLockReaderCount
- ENDIF
-
- ;
- ; extern TaskID GetReadWriteLockWriterID(ReadWriteLock *theReadWriteLock)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION GetReadWriteLockWriterID
- ENDIF
-
- ;
- ; Counting semaphore routines
- ; CountingSemaphores currently have no options.
- ;
- ;
- ; extern OSStatus CreateCountingSemaphore(CountingSemaphore *theCountingSemaphore, LockOptions theOptions, SInt32 initialCount, SInt32 maximumCount)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION CreateCountingSemaphore
- ENDIF
-
- ;
- ; extern OSStatus DeleteCountingSemaphore(CountingSemaphore *theCountingSemaphore)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION DeleteCountingSemaphore
- ENDIF
-
- ;
- ; extern OSStatus WaitForCountingSemaphore(CountingSemaphore *theCountingSemaphore)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION WaitForCountingSemaphore
- ENDIF
-
- ;
- ; extern OSStatus SignalCountingSemaphore(CountingSemaphore *theCountingSemaphore)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION SignalCountingSemaphore
- ENDIF
-
- ;
- ; extern SInt32 GetCountingSemaphoreCount(CountingSemaphore *theCountingSemaphore)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION GetCountingSemaphoreCount
- ENDIF
-
- ;
- ; extern SInt32 GetCountingSemaphoreMaxCount(CountingSemaphore *theCountingSemaphore)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION GetCountingSemaphoreMaxCount
- ENDIF
-
- ;
- ; extern ItemCount GetCountingSemaphoreWaiterCount(CountingSemaphore *theCountingSemaphore)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION GetCountingSemaphoreWaiterCount
- ENDIF
-
- ;
- ; Interrupt enabling and disabling. ** MAY ONLY BE CALLED FROM PRIVILEGED CODE!!! **
- ; Use very sparingly.
- ;
- ;
- ; extern InterruptState DisableInterrupts(void )
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION DisableInterrupts
- ENDIF
-
- ;
- ; extern void RestoreInterrupts(InterruptState theState)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION RestoreInterrupts
- ENDIF
-
- ;
- ; Atomic operations on 8-, 16-, and 32-bit entities.
- ; ** OPERATIONS THAT CROSS WORD (32-BIT) BOUNDARIES WILL FAIL!!! **
- ;
- ;
- ; extern Boolean CompareAndSwapAligned(UInt32 oldValue, UInt32 newValue, UInt32 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION CompareAndSwapAligned
- ENDIF
-
- ; Note: TestAndSet uses PPC bit ordering, zero is the high bit, and theBit ranges from 0 - FFFFFFFF.
- ;
- ; extern Boolean TestAndSet(UInt32 theBit, UInt8 *startAddress)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION TestAndSet
- ENDIF
-
- ;
- ; extern SInt8 IncrementAtomic8(SInt8 *value)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION IncrementAtomic8
- ENDIF
-
- ;
- ; extern SInt8 DecrementAtomic8(SInt8 *value)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION DecrementAtomic8
- ENDIF
-
- ;
- ; extern SInt8 AddAtomic8(SInt32 amount, SInt8 *value)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION AddAtomic8
- ENDIF
-
- ;
- ; extern UInt8 BitAndAtomic8(UInt32 mask, UInt8 *value)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitAndAtomic8
- ENDIF
-
- ;
- ; extern UInt8 BitOrAtomic8(UInt32 mask, UInt8 *value)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitOrAtomic8
- ENDIF
-
- ;
- ; extern UInt8 BitXorAtomic8(UInt32 mask, UInt8 *value)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitXorAtomic8
- ENDIF
-
- ;
- ; extern SInt16 IncrementAtomic16Aligned(SInt16 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION IncrementAtomic16Aligned
- ENDIF
-
- ;
- ; extern SInt16 DecrementAtomic16Aligned(SInt16 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION DecrementAtomic16Aligned
- ENDIF
-
- ;
- ; extern SInt16 AddAtomic16Aligned(SInt32 theAmount, SInt16 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION AddAtomic16Aligned
- ENDIF
-
- ;
- ; extern UInt16 BitAndAtomic16Aligned(UInt32 theMask, UInt16 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitAndAtomic16Aligned
- ENDIF
-
- ;
- ; extern UInt16 BitOrAtomic16Aligned(UInt32 theMask, UInt16 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitOrAtomic16Aligned
- ENDIF
-
- ;
- ; extern UInt16 BitXorAtomic16Aligned(UInt32 theMask, UInt16 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitXorAtomic16Aligned
- ENDIF
-
- ;
- ; extern SInt32 IncrementAtomicAligned(SInt32 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION IncrementAtomicAligned
- ENDIF
-
- ;
- ; extern SInt32 DecrementAtomicAligned(SInt32 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION DecrementAtomicAligned
- ENDIF
-
- ;
- ; extern SInt32 AddAtomicAligned(SInt32 theAmount, SInt32 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION AddAtomicAligned
- ENDIF
-
- ;
- ; extern UInt32 BitAndAtomicAligned(UInt32 theMask, UInt32 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitAndAtomicAligned
- ENDIF
-
- ;
- ; extern UInt32 BitOrAtomicAligned(UInt32 theMask, UInt32 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitOrAtomicAligned
- ENDIF
-
- ;
- ; extern UInt32 BitXorAtomicAligned(UInt32 theMask, UInt32 *theValue)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION BitXorAtomicAligned
- ENDIF
-
- ; Atomic primitives for singly linked list manipulation.
- ;
- ; extern void PushListElementAtomic(void *theListHead, void *theListElement, UInt32 theLinkOffset)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION PushListElementAtomic
- ENDIF
-
- ;
- ; extern void *PopListElementAtomic(void *theListHead, UInt32 theLinkOffset)
- ;
- IF GENERATINGCFM THEN
- IMPORT_CFM_FUNCTION PopListElementAtomic
- ENDIF
-
- ENDIF
- ENDIF ; __SYNCHRONIZATION__
-
-